﻿package hunterCommonlib.link 
{
	
	/**
	 * ...
	 * @author ...
	 */
	public class DLinkNode 
	{
		protected var _prev:DLinkNode;
		protected var _next:DLinkNode;
		public var data:Object;
		protected var _hasIn:Boolean;
		protected var _inLink:DLink;
		public function DLinkNode(data:*) 
		{
			this.data = data;
			_prev = _next = null;
			_hasIn = false;
		}
		public function get prev():DLinkNode {
			return _prev
		}
		public function set prev(node:DLinkNode):void {
			_prev = node;
		}
		public function get next():DLinkNode {
			return _next;
		}
		public function set next(node:DLinkNode):void {
			_next = node;
		}
		public function get hasIn():Boolean {
			return _hasIn
		}
		public function set hasIn(boolean:Boolean):void {
			_hasIn = boolean;
		}
		public function  insertPrev(node:DLinkNode):void {
			if (_prev != null) {
				_prev.next = node;
			}
			node.prev = _prev;
			node.next = this;
			_prev = node;
			node.hasIn = true;
		}
		public function insertNext(node:DLinkNode):void {
			if (_next != null) {
				_next.prev = node;
			}
			node.next = _next;
			node.prev = this;
			_next = node;
			node.hasIn = true;
		}
		public function get length():uint {
			var len:uint = 1;
			var node:DLinkNode
			for (node = _prev; node != null; node = node.prev) {
				len++
			}
			for (node = _next; node != null; node = node.next) {
				len++
			}
			return len;
		}
		public function remove():void {
			if (_prev != null) {
				_prev.next = _next;
			}
			if (_next != null) {
				_next.prev = _prev;
			}
			_prev = _next = null;
			hasIn = false;
		}
		public function toString():String {
			 return "[DLinkNode,data=" + data + "]";

		}
	}
	
}